import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Vant from 'vant';
import 'vant/lib/index.css';

Vue.use(Vant);
import '@/utils/modules/setRem.js'

import '@/assets/css/common.css'
import $utils from '@/utils/utils.js' //全局工具类utils

import $axios from '@/axios/axios.js' //axios的二次封装
import $Api from '@/axios/api.js' //引入api，所有的访问接口
import wx from 'weixin-js-sdk'


Vue.prototype.$wx = wx;
Vue.prototype.$axios = $axios; //挂载axios
Vue.prototype.$api = $Api; //挂载api
Vue.prototype.$utils = $utils; // 挂载utils

/* 路由发生变化修改页面title */
router.beforeEach((to, from, next) => {
    document.title = to.meta.title

    next()
    return 
    
    let baseInfo = store.state.app.baseInfo
    let encryptUrl = window.location.href
    // console.log("站点信息",baseInfo);
    if (baseInfo) {
        if (baseInfo.websiteNameTitle) {
            document.title = baseInfo.websiteNameTitle + '-' + to.meta.title
        } else {
            document.title = to.meta.title
        }
        if (baseInfo.enableTag == 0 && to.path !== '/error') {
            next('/error')
        } else {
            next()
        }
    } else {
        $Api.app.getSiteApi({
            encryptUrl: encryptUrl
        }).then((res) => {
            console.log("站点基本信息", res);
            store.commit('setBaseInfo', res.data)
            if (res.data?.websiteNameTitle && res.data.websiteNameTitle != '' && res.data.websiteNameTitle != null) {
                document.title = res.data.websiteNameTitle + '-' + to.meta.title
            } else {
                document.title = to.meta.title
            }
            if (res.data.enableTag == 0 && to.path !== '/error') {
                next('/error')
            } else {
                next()
            }
        }).catch((err) => {
            document.title = to.meta.title
            next()
        });
    }
})

Vue.config.productionTip = false

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
